//
//  WMH_WSBS_ItemListDetail_ViewController.m
//  EpointFrame5
//
//  Created by AndLi on 15/4/28.
//  Copyright (c) 2015年 Epoint. All rights reserved.
//

#import "WMH_WSBS_InfoDetail_ViewController.h"

#define TaskId_GetWsbsInfoDetail 1

@interface WMH_WSBS_InfoDetail_ViewController ()<UIWebViewDelegate>
{
    NSString *infoid;
    NSString *isneedurl;
}
@end

@implementation WMH_WSBS_InfoDetail_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    infoid    = [self.passParam objectForKey:@"infoid"];
    isneedurl = @"0";
    [self getWsbsInfoDetail];
}

-(void)getWsbsInfoDetail{
    [self showMBPHUD];
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:infoid        forKey:@"infoid"];
    [param setObject:isneedurl     forKey:@"isneedurl"];
    [self startTask:@"Task_GetWsbsInfoDetail" withParams:param withTaskId:TaskId_GetWsbsInfoDetail];
}

-(void)refreshUIWithThreadGuid:(int)taskId andData:(NSObject *)obj{
    [self hideMBPHUD];
    //处理异常信息
    NSMutableArray *arr = (NSMutableArray*)obj;
    if (![[arr objectAtIndex:0]isEqualToString:@"1"]) {
        [self toastMessage:[arr objectAtIndex:1]];
        return;
    }
    
    if (taskId==TaskId_GetWsbsInfoDetail) {
        
        NSString *result = [arr objectAtIndex:2];
        
        if([result rangeOfString:@"title"].location != NSNotFound){
            NSString *newscontent_fontsize = [DBFrameService getConfigValue:WMH_NewsContent_FontSize];
            //注意：css拼接中使用%%，进行百分号的格式化处理
            NSString * mycss =[NSString stringWithFormat:@"<style>p{margin:0px;padding:0px;}#news_outline {font-family:System;color: #5a5a5a; font-size:14px;text-align:left;padding-bottom:16px;padding-top:4px;}.ParagraphIndent img,p img{width:100%%;max-width:100%%;display:block;margin-bottom: 10px;}.ParagraphIndent,p,P{-webkit-box-sizing:border-box;box-sizing:border-box; width:100%%; padding:0 10px; letter-spacing:0.1px;color:#121212;text-indent:2em;font-size:%@px;line-height:150%%; overflow: hidden;word-wrap:break-word; word-break: bre-all;height:auto;zoom:1;text-align:justify;text-justify:inter-ideograph;padding-left:2px;font-family:System;}#news_title {font-weight:bold;text-align:left;-webkit-box-sizing:border-box;box-sizing:border-box; width:100%%;letter-spacing:0.1px;color:#121212;font-size:20px;line-height:120%%; overflow: hidden;word-wrap:break-word; word-break: bre-all;height:auto;zoom:1;text-align:justify;text-justify:inter-ideograph;font-family:System;padding-right:6px};</style>",newscontent_fontsize];
            
            result =[result stringByReplacingOccurrencesOfString:@"<![CDATA[" withString:@""];
            result= [result stringByReplacingOccurrencesOfString:@"]]>" withString:@""];
            
            NSString *title         = [EpointStringUtil getXMLFormatedAttribute:result :@"title"];
            NSString *infodate      = [EpointStringUtil getXMLFormatedAttribute:result :@"infodate"];
            NSString *infocontent   = [EpointStringUtil getXMLFormatedAttribute:result :@"infocontent"];
            
            NSString *disContent = [NSString stringWithFormat:@"%@<div id='news_title'>%@</div><div id='news_outline'>%@ %@</div>%@<br />",mycss,title,@"",[self dealDate:infodate],infocontent];
            
            UIWebView *mWebView = [[UIWebView alloc]initWithFrame:[self getFullContentFrame]];
            [mWebView loadHTMLString:disContent baseURL:nil];
            mWebView.delegate = self;
            [self.view addSubview:mWebView];
        }
        
    }
    
}
#pragma 处理日期类型
-(NSString *)dealDate:(NSString *)_infoDate{
    if([_infoDate rangeOfString:@"/"].location!=NSNotFound || [_infoDate rangeOfString:@"-"].location!=NSNotFound){
        NSArray *str = [_infoDate componentsSeparatedByString:@" "];
        NSString *temp = [NSString stringWithFormat:@"%@: %@",@"发布时间",[str objectAtIndex:0]];
        return  temp;
    }else{
        return [NSString stringWithFormat:@"%@: %@",@"发布时间",_infoDate];
    }
}

@end
